import QtQuick 1.0
import "../Components"

DialogBase {
    id: _root
    width: _item.width + 10 + 10
    height: titleHeight + _item.height + 10 + 10
    x: 0
    y: 0

    signal clickOkButton        //OKボタンのイベント
    signal clickCancelButton    //cancelボタンのイベント

    //ダイアログの本文
    property alias dialogMessage: _text.text

    property alias visibleCancel: _buttonCancel.visible


    // 表示された時の処理
    function viewEvent(){
        _buttonOk.forceActiveFocus();
    }

    Item {
        id: _item
        x: 10
        width: _areaButton.width * (visibleCancel ? 1 : 2)  //ボタンが１つの場合は横幅広げる
        height: _areaButton.height + _areaButton.spacing + _text.height + 10
        anchors.top: _root.titleBottom
        anchors.topMargin: 10

        Text {
            id: _text
            x: 0
            y: 0
            width: parent.width
            text: "message"
            wrapMode: Text.WordWrap

            font.pointSize: 12
            color: "#ffffff"

            onTextChanged: {
                if(_item.width < width){
                    _item.width = width;
                }
            }
        }

        Row {
            id: _areaButton
            anchors.top: _text.bottom
            anchors.topMargin: 10
            anchors.horizontalCenter: _item.horizontalCenter

            spacing: 5

            Button {
                id: _buttonOk
                width: 100
                height: 25

                text: "O K"

                onClicked : {
                    clickOkButton();
                }

                Keys.onTabPressed: {
                    if(_buttonCancel.visible){
                        _buttonCancel.forceActiveFocus();
                    }
                }
                Keys.onPressed: {
                    switch(event.key){
                    case Qt.Key_Escape:
                        clickCancelButton();
                        break;
                    case Qt.Key_Enter:
                    case Qt.Key_Return:
                        clickOkButton();
                        break;
                    default:
                        break;
                    }
                }
            }

            Button {
                id: _buttonCancel
                width: 100
                height: 25

                text: "Cancel"

                onClicked : {
                    clickCancelButton();
                }

                Keys.onTabPressed: {
                    _buttonOk.forceActiveFocus();
                }
                Keys.onPressed: {
                    switch(event.key){
                    case Qt.Key_Escape:
                    case Qt.Key_Enter:
                    case Qt.Key_Return:
                        clickCancelButton();
                        break;
                    default:
                        break;
                    }
                }
            }
        }

    }
}
